import java.util.Arrays;
import java.util.Scanner;

/**
 *  哈夫曼树
 */
public class HuffumanTree {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = 0;
        long sum = 0;
        int n = sc.nextInt();
        int p[] = new int[n];
        for (int i = 0 ; i < n ; i++){
            p[i] = sc.nextInt();
        }
        Arrays.sort(p,0,n);
        for (int i = 1 ; i < n ; i++){
            Arrays.sort(p,0,n);
            p[i] = p[i-1] + p[i];
            a = p[i];
            sum += a;
        }
        System.out.println(sum);
    }
}
